#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:zhangcong
# Email:zc_92@sina.com


from urllib.parse import quote_plus
from pymongo import MongoClient


def get_db_obj():
    # user = "zhangcong"
    # password = "F8a4C7@c2Cdd013ACDE^"
    # host = "111.204.117.100"
    #
    # uri = "mongodb://%s:%s@%s" % (
    #     quote_plus(user),
    #     quote_plus(password), host
    # )
    # db = MongoClient(uri).myblog

    print("mongodb://%s:%s@%s" % (quote_plus("zhangcong"), quote_plus("F8a4C7@c2Cdd013ACDE^"), "MongoDB"))
    MongoDB = MongoClient("mongodb://%s:%s@%s" % (quote_plus("zhangcong"), quote_plus("F8a4C7@c2Cdd013ACDE^"), "MongoDB")).myblog

    return MongoDB

# db.user.remove()
# db.user.insert({"username": "zhangcong", "password": "202cb962ac59075b964b07152d234b70"})
#

if __name__ == '__main__':

    db = get_db_obj()
    result = db.user.find()

    for i in result:
        print(i, type(i))
        print(i["_id"])
